package com.lxc.infrastructure.persistent.repository;

import com.lxc.domain.api.model.entity.ApiEntity;
import com.lxc.domain.api.repository.IApiRepository;
import com.lxc.infrastructure.persistent.dao.HttpStatementDao;
import com.lxc.infrastructure.persistent.po.HttpStatement;
import org.springframework.stereotype.Repository;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * @author lxc18
 * @date 2024/12/11 19:26
 * @description ApiRepository
 */
@Repository
public class ApiRepository implements IApiRepository {

    @Resource
    HttpStatementDao httpStatementDao;
    @Override
    public List<ApiEntity> getHttpStatementList() {
        List<HttpStatement> allHttpStatement = httpStatementDao.getAllHttpStatement();
        ArrayList<ApiEntity> apiEntities = new ArrayList<>(allHttpStatement.size());
        for(HttpStatement httpStatement:allHttpStatement){
            ApiEntity apiEntity = new ApiEntity();
            apiEntity.setApplication(httpStatement.getApplication());
            apiEntity.setUri(httpStatement.getUri());
            apiEntity.setHttpCommandType(httpStatement.getHttpCommandType());
            apiEntity.setInterfaceName(httpStatement.getInterfaceName());
            apiEntity.setMethodName(httpStatement.getMethodName());
            apiEntity.setAuth(httpStatement.getAuth());
            apiEntity.setParameterType(httpStatement.getParameterType());
            apiEntities.add(apiEntity);

        }
        return apiEntities;
    }
}
